﻿using Irony.Parsing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NMF.Languages.AnyText.ClassConstruction
{
    public class ClassBuilderContext : IEquatable<ClassBuilderContext>
    {
        public Class CurrentClass { get; set; }
        public BnfTermList LastTermList { get; private set; }

        public ClassBuilderContext TakeBnfList(BnfTermList termList)
        {
            var context = new ClassBuilderContext();
            context.CurrentClass = CurrentClass;
            context.LastTermList = termList;
            return context;
        }

        public ClassBuilderContext SwitchContextClass(Class nextClass)
        {
            var context = new ClassBuilderContext();
            context.CurrentClass = nextClass;
            context.LastTermList = this.LastTermList;
            return context;
        }

        public bool Equals(ClassBuilderContext other)
        {
            if (other != null)
            {
                return CurrentClass == other.CurrentClass && LastTermList == other.LastTermList;
            }
            else
            {
                return false;
            }
        }

        public override bool Equals(object obj)
        {
            return Equals(obj as ClassBuilderContext);
        }

        public override int GetHashCode()
        {
            var i = 0;
            if (CurrentClass != null) i ^= CurrentClass.GetHashCode();
            if (LastTermList != null) i ^= LastTermList.GetHashCode();
            return i;
        }
    }
}
